package com.lanou3g.code0531;

import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UserServlet", urlPatterns = "/user")
public class UserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/json;charset=utf-8");
        //1.获取参数
        //2.调用controller
        User user = new User();
        response.getWriter().println("");
        user.setUsername("张三");
        user.setAge(18);
        String[]hobbies={"eat","drink","play"};
        user.setHobbies(hobbies);
        //3.返回数据
        Gson gson=new Gson();
        String data=gson.toJson(user);
        response.getWriter().println(data);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
